package tests;

import static org.junit.Assert.*;

import java.awt.Color;

import org.junit.Before;
import org.junit.Test;

import MULE.Model.Inventory;
import MULE.Model.Player;
import MULE.Model.Race;
import MULE.Model.Resource;
import MULE.Model.Store;

/**
 * This class tests the Store class' sell method
 * 
 * @ author William Baldwin @ version 1.0 11.18.2013
 */

/*
 * Cases to check for: 1) Removes the proper amount of the right resource from
 * player inventory when it is available Adds the proper amount of money to
 * player inventory (Design assumes store can always pay for resources) Adds the
 * proper amount of the right resource to the store
 * 
 * 2) Runs as above even when the player has only the exact amount of the
 * resource
 * 
 * 3) No changes if the player has insufficient resources
 * 
 * Resource values: MONEY(1), FOOD(30), ENERGY(25), SMITHORE(50), CRYSTITE(100),
 * MULE(175);
 */
public class StoreTest2 {
	private Player p;

	@Before
	public void setUp() {
		p = new Player(1, "Test", Race.HUMAN, Color.RED);
		p.getInventory().add(Resource.FOOD, 10);
		p.getInventory().add(Resource.ENERGY, 4);
		p.getInventory().add(Resource.SMITHORE, 5);
		p.getInventory().add(Resource.CRYSTITE, 5);
		Store.setStorehouse(new Inventory(100, 0, 0, 0, 0));
	}

	@Test
	public void test1() { // See if it works away from edge cases
		Store.sell(p, Resource.FOOD, 2); // sells two food for a profit of 60
		assertEquals(60, p.getMoney());
		assertEquals(8, p.getInventory().getAmount(Resource.FOOD));// after
																	// selling 2
																	// remaining
																	// food
																	// should be
																	// 8
		assertEquals(2, Store.getStorehouse().getAmount(Resource.FOOD));
	}

	@Test
	public void test2() { // Runs at edge case of player having exact amount of
							// resources
		Store.sell(p, Resource.ENERGY, 4); // sells four energy for a profit of
											// 100
		assertEquals(100, p.getMoney());
		assertEquals(0, p.getInventory().getAmount(Resource.ENERGY));// after
																		// selling
																		// 4
																		// remaining
																		// energy
																		// should
																		// be 0
		assertEquals(4, Store.getStorehouse().getAmount(Resource.ENERGY));
	}

	@Test
	public void test3() { // No changes when player has insufficient resources
		Store.sell(p, Resource.SMITHORE, 10); // sells four energy for a profit
												// of 100
		assertEquals(0, p.getMoney());
		assertEquals(5, p.getInventory().getAmount(Resource.SMITHORE));// No
																		// sale,
																		// no
																		// change
		assertEquals(0, Store.getStorehouse().getAmount(Resource.SMITHORE));
	}

	@Test
	public void test4() { // The last tests are simply checks to make sure the
							// correct amount of money is given for every
							// resource.
		Store.sell(p, Resource.SMITHORE, 4); // sells four smithore for a profit
												// of 200
		assertEquals(200, p.getMoney());
		assertEquals(1, p.getInventory().getAmount(Resource.SMITHORE));// after
																		// selling
																		// 4
																		// remaining
																		// smithore
																		// should
																		// be 1
		assertEquals(4, Store.getStorehouse().getAmount(Resource.SMITHORE));
	}

	@Test
	public void test5() {
		Store.sell(p, Resource.CRYSTITE, 1); // sells one crystite for a profit
												// of 100
		assertEquals(100, p.getMoney());
		assertEquals(4, p.getInventory().getAmount(Resource.CRYSTITE));// after
																		// selling
																		// 1
																		// remaining
																		// crystite
																		// should
																		// be 4
		assertEquals(1, Store.getStorehouse().getAmount(Resource.CRYSTITE));
	}
}
